package com.csu.servlet;

import com.csu.entiry.Book;
import com.csu.entiry.BorrowInfo;
import com.csu.service.BorrowInfoService;
import com.csu.service.impl.BorrowInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "GetOneBorrowInfoServlet", urlPatterns = "/GetOneBorrowInfoServlet")
public class GetOneBorrowInfoServlet extends HttpServlet {
    private BorrowInfoService borrowInfoService = new BorrowInfoServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int borrowId = Integer.parseInt(req.getParameter("borrowId"));
//        if (id == null || "".equals(id)) {
//            response.sendRedirect(request.getContextPath() + "/index.js");
//        }
        BorrowInfo borrowInfo = borrowInfoService.getByBorrowId(borrowId);
        req.getSession().setAttribute("editBorrowInfo", borrowInfo);
        resp.sendRedirect(req.getContextPath() + "/updateBorrowInfo.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
